package org.idea.qiyu.framework.threadpool.dynamic.controller;

import lombok.SneakyThrows;
import org.idea.qiyu.framework.threadpool.dynamic.Application;
import org.idea.qiyu.framework.threadpool.dynamic.config.ApplicationProperties;
import org.idea.qiyu.framework.threadpool.dynamic.executor.QiyuExecutor;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author linhao
 * @Date created in 7:21 下午 2021/10/25
 */
@RestController
@RequestMapping(value = "/")
public class QiyuThreadPoolController {

    @Resource
    private QiyuExecutor qiyuExecutor;

    @Resource
    private ApplicationContext applicationContext;

    @GetMapping(value = "/do-test")
    public String doTest(){
        qiyuExecutor.execute(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                System.out.println("this is end");
                Thread.sleep(10000);
            }
        });
        qiyuExecutor.getTaskInfo();
        System.out.println("this is test");
        return "success";
    }

    @GetMapping(value = "/add-max-size")
    public void addMaxSize(int maxSize,int coreSize){
        qiyuExecutor.setCorePoolSize(coreSize);
        qiyuExecutor.setMaximumPoolSize(maxSize);
    }


}
